#define _CRT_SECURE_NO_WARNINGS 1

class NeighborSum {
public:
    NeighborSum(vector<vector<int>>& grid) {
        //this->adj(100, 0);
        //this->dia(100, 0);
        int n = grid.size();
        for (int i = 0; i < n; i++)
        {
            int m = grid[i].size();
            for (int j = 0; j < m; j++)
            {
                for (int k = 0; k < 4; k++)
                {
                    int a = i + dx[k];
                    int aa = i + ddx[k];
                    int b = j + dy[k];
                    int bb = j + ddy[k];
                    if (a >= 0 && a < m && b >= 0 && b < m) adj[grid[i][j]] += grid[a][b];
                    if (aa >= 0 && aa < m && bb >= 0 && bb < m) dia[grid[i][j]] += grid[aa][bb];
                }
            }
        }
    }

    int adjacentSum(int value) {
        return adj[value];
    }

    int diagonalSum(int value) {
        return dia[value];
    }
private:
    int dx[4] = { 0, 0, 1, -1 };
    int dy[4] = { 1, -1, 0, 0 };
    int ddx[4] = { 1, 1, -1, -1 };
    int ddy[4] = { 1, -1, 1, -1 };
    vector<int> adj = vector<int>(100);
    vector<int> dia = vector<int>(100);
};

/**
 * Your NeighborSum object will be instantiated and called as such:
 * NeighborSum* obj = new NeighborSum(grid);
 * int param_1 = obj->adjacentSum(value);
 * int param_2 = obj->diagonalSum(value);
 */